<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class Contact extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->output->nocache();
		$this -> form_validation -> set_error_delimiters('<p class="help-block danger">', '</p>');
	}
	public function index() {
		$data['title'] = "Contact Us";
		$this -> form_validation -> set_rules('email', 'Email', 'required|valid_email');
		$this -> form_validation -> set_rules('subject', 'Subject', 'required');
		if ($this -> form_validation -> run() === FALSE) {
			$data['feature_jobs'] = $this -> model_jobs -> fearture_job();
			$this -> load -> view(F_MASTER . "index", $data);
		} else {
			
			$email = $this -> input -> post('email');
			$subject = $this -> input -> post('subject');
			$description = $this -> input -> post('description');

			$is_sent_mail = $this -> is_sent_mail_to_owner_website($email, $subject, $description);
			if ($is_sent_mail) {
				$this -> session -> set_flashdata('success', 'Your email  was sent success !.');
				redirect('contact');
			} else {
				$this -> session -> set_flashdata('error', 'Your email was sent fail !.');
				redirect('contact');
			}
		}
	}

	public function is_sent_mail_to_owner_website($email, $subject, $description) {
		$this -> load -> library('email');

		$this -> email -> from($email, $email);
		$this -> email -> to('info@jobpending.com');
		$this -> email -> cc('jobpending.info@gmail.com');
		//$this->email->bcc('them@their-example.com');

		$this -> email -> subject($subject);
		$this -> email -> message($description);

		$is_sent=$this -> email -> send();

		if ($is_sent) {
			return TRUE;
		} else {
			echo $this->email->print_debugger();
			exit;
			return FALSE;
		}
	}

}
